
const { JSDOM, Document } = require("jsdom")
const cryptjs = require('crypto-js')
import { registerData } from './interfaces/types'
const initCycleTLS = require('cycletls');


class Extension {
    url: string;
    regData: registerData | null = null;
    constructor(url: string) {
        this.url = url;
    }
    setHtml(html: string): Document {
        return new JSDOM(html).window.document;
    }
    async getRequest() {
        return await initCycleTLS();
    }
    //设置数据
    registerSetting() {

    }
    // 发送请求
    async request(url?: string, options?: any) {
        url = url || this.url
        if (!options) options = {};
        options = { ...options, "ja3": '771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0', };
        options.method = options.method ?? "get"
        const request = await this.getRequest()
        let response: {
            'status': string,
            'body': string,
            'headers': string,
            'finalUrl': string
        };
        try {
            response = await request(url, options, options.method)    
        } catch (error) {
            return null
        } finally {
            request.exit()
        }
        return response.body;
    }
    search(kw: string, page: number): unknown {
        throw new Error("not implement");
    }
    info(url: string): unknown {
        throw new Error("not implement");
    }
    watch(url: string): unknown {
        throw new Error("not implement");
    }
    latest(): unknown {
        throw new Error("not implement");
    }
    checkUpdate(url: string): string {
        return "";
    }
}

export default Extension